<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>换肤效果</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .toggleBtn {
      margin: 40px;
      outline: none;
      border: none;
      padding: 5px;
      background: #ccc;
    }

    .img-box {
      margin: 0 auto;
      width: 1300px;
      height: 0;
      background: #dddddd;
    }

    .img-box img {
      display: none;
      margin: 25px 33px 0 0;
      float: left;
      width: 300px;
      height: 190px;
    }

    .img-box img:last-child {
      margin-right: 0;
    }

    .active {
      height: 242px;
    }

    .active img {
      display: block;
    }
  </style>
</head>

<body>
  <div class="img-box">
    <img src="./image/001.jpg" alt="">
    <img src="./image/002.jpg" alt="">
    <img src="./image/003.jpg" alt="">
    <img src="./image/004.jpg" alt="">
  </div>
  <button class="toggleBtn">换肤</button>

  <script>
    let toggleBtn = document.querySelector(".toggleBtn") //换肤按钮
    let img_box = document.querySelector(".img-box") //图片盒子

    //点击换肤按钮，显示图片盒子
    toggleBtn.onclick = function () {
      img_box.className = "img-box active"
      //点击图片盒子中的img，把点击到的img的src更换为body的背景
      let imgs = img_box.querySelectorAll("img")
      imgs.forEach(function (item, i) {
        item.onclick = function () {
          //点击了那一个img，就把body的背景更换为img的路径
          console.log(i);
          document.body.style.background = `url(image/00${i+1}.jpg) no-repeat center`
          document.body.style.backgroundSize = "100%"
        }
      })
    }
  </script>
</body>

</html>